home *** CD-ROM | disk | FTP | other *** search
/ Gigarom 1 / Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso / FILES / HYP / E-G / Externals.cpt / Externals / card_7952.txt < prev    next >
Text File  |  1989-02-26  |  5KB  |  139 lines

  1. -- card: 7952 from stack: in
  2. -- bmap block id: 0
  3. -- flags: 0000
  4. -- background id: 2795
  5. -- name: SubLaunch
  6.  
  7.  
  8. -- part contents for background part 1
  9. ----- text -----
  10. XFCN
  11.  
  12. -- part contents for background part 22
  13. ----- text -----
  14. SubLaunch(programName,docName)
  15.  
  16. -- part contents for background part 13
  17. ----- text -----
  18.     ‚Ä¢  SubLaunch(programName,docName)* - sublaunches the program with optional attached 
  19.         document.  Both HyperCard and the specified program will then be running, memory 
  20.         permitting (at least 2 Meg!).  If the arguments have no colons in them (not a pathname), 
  21.         then the ‚ÄúLook for applications in:‚Äù¬†etc. cards in the Home stack are consulted. 
  22.  
  23. SubLaunch return 0 for success, negative numbers for Operating System errors, and small positive numbers for parameter errors, or lack of memory. To see how to handle this, and how the XFCNs can be used in concert, take a look at the ‚ÄúInvokeApplication‚Äù and ‚ÄúOsErr‚Äù handlers* below. InvokeApplication also fixes HyperCard bugs* when under MultiFinder.
  24.  
  25. on InvokeApplication progName,docName,noSubLaunch
  26.   global documents
  27.   if MultiFinder() is false then
  28.     if docName is empty then
  29.       open progName
  30.     else
  31.       open docName with progName
  32.     end if
  33.   else
  34.     if IsRunning(progName) is true then
  35.       -- Can't attach a document in this case without invoking
  36.       -- Tempo or QuicKeys. See the ‚ÄúPostEvent‚Äù stack for details.
  37.       doMenu progName
  38.     else
  39.       -- Not running. Launch or sublaunch it.
  40.       if the shiftKey is down or noSubLaunch is true then
  41.         -- Override: don't sublaunch, just do a normal launch.
  42.         if docName is not empty then
  43.           -- Need to move the document up to the volume root for this
  44.           -- to work properly due to MultiFinder/Hypercard bug.
  45.           if NumberOfChars(":",docName) is 0 then
  46.             -- Filename needs expanding
  47.             put GetFullPath(docName,documents) into docName
  48.             if docName is empty then
  49.               -- one reason for this would be a previous call that
  50.               -- moved the document up to the root, and the root isn't
  51.               -- on the document search path
  52.               answer "Can't find the document" with "OK"
  53.               exit InvokeApplication
  54.             end if
  55.           end if -- end NumberOfChars
  56.           
  57.           -- Is this document at the root of the volume?
  58.           if FileAtRoot(docName) is false then
  59.             -- Need to move it to the root. Start by computing the
  60.             -- name of the volume.
  61.             put VolumeName(docName) into vol
  62.             if vol is empty then exit InvokeApplication
  63.             
  64.             put MoveFile(docName,vol) into err
  65.             if err is not 0 then
  66.               OsErr err -- report file i/o error
  67.               exit InvokeApplication
  68.             end if
  69.             
  70.             -- Document is now at the root. All we need to do is find
  71.             -- out the new name for the document.
  72.             put vol & LastPathComponent(docName) into docName
  73.           end if -- end FileAtRoot
  74.           
  75.           open docName with progName
  76.         else
  77.           -- No document. Just run the application.
  78.           open progName
  79.         end if -- end docName not empty test
  80.         
  81.         exit InvokeApplication
  82.       end if      -- end shiftKey/override
  83.       
  84.       if docName is empty then
  85.         put SubLaunch(progName) into err
  86.       else
  87.         put SubLaunch(progName,docName) into err
  88.       end if
  89.       if err is not 0 then
  90.         if err < 0 then
  91.           OsErr err
  92.         else if err is 1 then
  93.           -- Parameter error?
  94.           answer "Parameter error in sublaunch call" with "OK"
  95.         else if err is 2 then
  96.           -- System error encountered in sublaunch
  97.           answer "Insufficient memory (or already running?)" ¬¨
  98.           with "Failed"
  99.         end if
  100.       end if
  101.     end if
  102.   end if
  103. end InvokeApplication
  104.  
  105. -- OsErr: for displaying Operating system error codes returned by
  106. -- Sublaunch, RenameFile, MoveFile and DeleteFile XFCNs.
  107.  
  108. on OsErr err
  109.   -- Translate the most common ones
  110.   if err > 0 then -- XFCN convention
  111.     put "Parameter error with function" into errstr
  112.   else if err is -59 then
  113.     put "Problem during rename" into errstr
  114.   else if err is -54 then
  115.     put "Attempt to open locked file for writing" into errstr
  116.   else if err is -46 then
  117.     put "Volume locked by software" into errstr
  118.   else if err is -45 then
  119.     put "File locked" into errstr
  120.   else if err is -44 then
  121.     put "Volume locked by hardware" into errstr
  122.   else if err is -43 then
  123.     put "File not found" into errstr
  124.   else if err is -37 then
  125.     put "Bad volume or file name" into errstr
  126.   else if err is -36 then
  127.     put "I/O error" into errstr
  128.   else if err is -35 then
  129.     put "No such volume" into errstr
  130.   else if err is -34 then
  131.     put "Disk is full" into errstr
  132.   else if err is -49 then
  133.     put "File already open for writing" into errstr
  134.   else
  135.     put "Failed with error" && err into errstr
  136.   end if
  137.   answer errstr with "OK"
  138. end OsErr
  139.